package com.leo.ktvplayer.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 *
 */
public class JsonUtil {

    private static final String TAG = "JSON工具";

    private static Gson gson = new GsonBuilder().setDateFormat(
            "yyyy-MM-dd HH:mm:ss").serializeSpecialFloatingPointValues().create();

    public static Gson getGson() {
        return gson;
    }

    public static String objToJsonStr(Object obj) {
        try {
            return gson.toJson(obj);
        } catch (Exception e) {

        }
        return null;
    }

    @SuppressWarnings("unchecked")
    public static <T> T jsonStrToObj(Class<T> clz, String source) {

        try {
            return (T) gson.fromJson(source, clz);
        } catch (Exception e) {

        }
        return null;
    }


}
